<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>题海 - 主页面</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
    <div class="container">
        <a class="navbar-brand" href="/htmls">游戏中心</a>
        <div class="navbar-collapse">
            <ul class="navbar-nav me-auto">
                <li class="nav-item">
                    <a class="nav-link active" href="#">题库练习</a>
                </li>
            </ul>
            <div th:if="${session.currentUser != null}">
                欢迎：<span th:text="${session.currentUser.studentName}"></span>
            </div>
            <a href="/logout" class="btn btn-outline-light">退出</a>
        </div>
    </div>
</nav>
<nav>
    <div>
        <a href="game.html">游戏中心</a>
        <a href="#">题库练习</a>
    </div>
    <div class="user-info" id="user-info">
        <!-- 用户信息将通过JavaScript动态加载 -->
    </div>
</nav>

<div class="content">
    <h1>欢迎来到题海学习平台</h1>

    <div class="game-cards">
        <a href="game.html" class="game-card">
            <img src="/img/game-icon.png" alt="游戏图标">
            <h3>游戏中心</h3>
            <p>放松一下，玩个小游戏</p>
        </a>
        <a href="#" class="game-card">
            <img src="/img/question-icon.png" alt="题库图标">
            <h3>题库练习</h3>
            <p>挑战各种题目</p>
        </a>
    </div>
</div>
<script>
    document.addEventListener('DOMContentLoaded', function() {
        // 从sessionStorage获取用户信息
        const userData = sessionStorage.getItem('currentUser');
        if (userData) {
            const user = JSON.parse(userData);
            document.getElementById('user-info').innerHTML = `
                欢迎，${user.userName} | <a href="../login.html" onclick="logout()">退出</a>
            `;
        } else {
            // 如果没有用户信息，跳转到登录页
            window.location.href = 'login.html';
        }
    });

    function logout() {
        sessionStorage.removeItem('currentUser');
    }
</script>
</body>
</html>